package cn.tedu.baking.controller;

import cn.tedu.baking.mapper.BannerMapper;
import cn.tedu.baking.pojo.vo.BannerAdminVO;
import cn.tedu.baking.pojo.vo.BannerVO;
import cn.tedu.baking.response.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *  对于轮播图请求处理的控制器类:
 */
@RestController
@RequestMapping("/v1/banners/")
public class BannerController {
    @Autowired
    BannerMapper bannerMapper;
    //http://localhost:8080/v1/banners/
    @GetMapping("")
    //贴个"便利贴"(注解)
    public JsonResult getBanners(){
        List<BannerVO> bannerVOS = bannerMapper.selectAll();
        return JsonResult.ok(bannerVOS);
    }

    @GetMapping("admin")
    public JsonResult getBannerAdmin(){

        List<BannerAdminVO> bannerAdminVOS = bannerMapper.selectForAdmin();

        return JsonResult.ok(bannerAdminVOS);
    }

    @PostMapping("{id}/delete")
    public JsonResult deleteById(@PathVariable Long id){

        bannerMapper.deleteById(id);

        return JsonResult.ok();
    }

}
